package com.iwunu.gateway.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.iwunu.gateway.service.LoginService;
import com.iwunu.gateway.service.OrgLoginService;
import com.iwunu.gateway.vo.LoginBindPhoneVo;
import com.iwunu.gateway.vo.LoginParamVo;
import com.iwunu.iot.common.constant.ResultCodeEnum;
import com.iwunu.iot.common.util.Result;
import com.iwunu.iot.common.wechat.OpenIdUtil;
/**
 * @author kinfeng
 * @date 2021/6/13 11:26 AM
 * @description
 */
@CrossOrigin
@RequestMapping("/org")
@Controller
@Api(tags = "短信，登录接口", description = "短信，登录接口")
public class OrgLoginController {

    @Autowired
    private OrgLoginService loginService;


    @RequestMapping(value = "/login",method= RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "商户登录接口")
    public ResponseEntity login(
            @ApiParam(value = "phone", required = true)@RequestParam String phone,
            @ApiParam(value = "password", required = true)@RequestParam String password
    ){
        Result result = null;
		try {
			result = loginService.login(phone,password);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/refreshToken",method= RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "刷新token")
    public ResponseEntity refreshToken(
            @ApiParam(value = "登录获取的token值", required = true)@RequestHeader String Authorization
    ){
        Result result = loginService.refreshToken(Authorization);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }



}
